namespace Framework.Migrations
{
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreated : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "User",
                c => new
                    {
                        UserId = c.Int(nullable: false, identity: true),
                        UserName = c.String(),
                        FirstName = c.String(),
                        LastName = c.String(),
                        Email = c.String(),
                        LrAccount = c.String(),
                        Balance = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Password = c.String(),
                        ActiveCode = c.Guid(nullable: false),
                        NumPin = c.Int(nullable: false),
                        Active = c.Boolean(nullable: false),
                        Roles = c.String(),
                        IsAdmin = c.Boolean(nullable: false),
                        Address = c.String(),
                        Country = c.String(),
                        Phone = c.String(),
                        Sex = c.String(),
                        BirthDay = c.String(),
                        CreatedTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.UserId);
            
            CreateTable(
                "SecurityLog",
                c => new
                    {
                        SecurityLogId = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        Action = c.String(),
                        CreatedTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.SecurityLogId)
                .ForeignKey("User", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "Deposit",
                c => new
                    {
                        DepositId = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        Amount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Batch = c.Long(nullable: false),
                        CreatedTime = c.DateTime(nullable: false),
                        Status = c.Boolean(nullable: false,defaultValue:false),
                    })
                .PrimaryKey(t => t.DepositId)
                .ForeignKey("User", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "WithDraw",
                c => new
                    {
                        WithDrawId = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        Amount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Approved = c.Boolean(nullable: false),
                        CreatedTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.WithDrawId)
                .ForeignKey("User", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "SecureUser",
                c => new
                    {
                        SecureUserId = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        IpAddress = c.String(),
                        CreatedTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.SecureUserId)
                .ForeignKey("User", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "Bet",
                c => new
                    {
                        BetId = c.Int(nullable: false, identity: true),
                        MatchId = c.Int(nullable: false),
                        UserId = c.Int(nullable: false),
                        MaxBet = c.Decimal(nullable: false, precision: 18, scale: 2),
                        CurrentBet = c.Decimal(nullable: false, precision: 18, scale: 2),
                        ScoreHomeBefore = c.Decimal(nullable: false, precision: 18, scale: 2),
                        ScoreAwayBefore = c.Decimal(nullable: false, precision: 18, scale: 2),
                        ScoreHomeAfter = c.Decimal(nullable: false, precision: 18, scale: 2),
                        ScoreAwayAfter = c.Decimal(nullable: false, precision: 18, scale: 2),
                        CreatedTime = c.DateTime(nullable: false),
                        Type = c.Int(nullable: false),
                        Status = c.Boolean(nullable: false,defaultValue:false),
                    })
                .PrimaryKey(t => t.BetId)
                .ForeignKey("Match", t => t.MatchId, cascadeDelete: true)
                .ForeignKey("User", t => t.UserId, cascadeDelete: true)
                .Index(t => t.MatchId)
                .Index(t => t.UserId);
            
            CreateTable(
                "Match",
                c => new
                    {
                        MatchId = c.Int(nullable: false, identity: true),
                        HomeScore = c.Decimal(nullable: false, precision: 18, scale: 2),
                        AwayScore = c.Decimal(nullable: false, precision: 18, scale: 2),
                        HomeTeamId = c.Int(nullable: false),
                        AwayTeamId = c.Int(nullable: false),
                        LeagueId = c.Int(nullable: false),
                        IsPlay = c.Int(nullable: false),
                        Status = c.Boolean(nullable: false,defaultValue:false),
                        CreatedTime = c.DateTime(nullable: false),
                        TimePlay = c.String(),
                        StartTime = c.DateTime(nullable: false),
                        EndTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.MatchId)
                .ForeignKey("SoccerTeam", t => t.HomeTeamId, cascadeDelete: true)
                .ForeignKey("SoccerTeam", t => t.AwayTeamId, cascadeDelete: false)
                .ForeignKey("League", t => t.LeagueId, cascadeDelete: true)
                .Index(t => t.HomeTeamId)
                .Index(t => t.AwayTeamId)
                .Index(t => t.LeagueId);
            
            CreateTable(
                "SoccerTeam",
                c => new
                    {
                        SoccerTeamId = c.Int(nullable: false, identity: true),
                        TeamName = c.String(),
                        Status = c.Boolean(nullable: false),
                        CreatedTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.SoccerTeamId);
            
            CreateTable(
                "League",
                c => new
                    {
                        LeagueId = c.Int(nullable: false, identity: true),
                        NameLeague = c.String(),
                        IsPlay = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.LeagueId);
            
            CreateTable(
                "BetDetail",
                c => new
                    {
                        BetDetailId = c.Int(nullable: false, identity: true),
                        BetId = c.Int(nullable: false),
                        OddsHome = c.Decimal(nullable: false, precision: 18, scale: 2),
                        OddsAway = c.Decimal(nullable: false, precision: 18, scale: 2),
                        OddsDraw = c.Decimal(nullable: false, precision: 18, scale: 2),
                        RateUnderOver = c.Decimal(nullable: false, precision: 18, scale: 2),
                        OddsUnder = c.Decimal(nullable: false, precision: 18, scale: 2),
                        OddsOver = c.Decimal(nullable: false, precision: 18, scale: 2),
                        OddsExactScore = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Type = c.Int(nullable: false),
                        CreatedTime = c.DateTime(nullable: false),
                        Status = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.BetDetailId)
                .ForeignKey("Bet", t => t.BetId, cascadeDelete: true)
                .Index(t => t.BetId);
            
            CreateTable(
                "UserBet",
                c => new
                    {
                        UserBetId = c.Int(nullable: false, identity: true),
                        BetDetailId = c.Int(nullable: false),
                        UserId = c.Int(nullable: false),
                        Odds = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Stake = c.Decimal(nullable: false, precision: 18, scale: 2),
                        UserWin = c.Decimal(nullable: false, precision: 18, scale: 2),
                        CreatedTime = c.DateTime(nullable: false),
                        Status = c.Boolean(nullable: false),
                        IsWin = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.UserBetId)
                .ForeignKey("User", t => t.UserId, cascadeDelete: true)
                .ForeignKey("BetDetail", t => t.BetDetailId, cascadeDelete: false)
                .Index(t => t.UserId)
                .Index(t => t.BetDetailId);
            
            CreateTable(
                "Chat",
                c => new
                    {
                        ChatId = c.Int(nullable: false, identity: true),
                        UserId = c.Int(nullable: false),
                        Body = c.String(),
                        IpAddress = c.String(),
                        CreatedTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.ChatId)
                .ForeignKey("User", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "Content",
                c => new
                    {
                        ContentId = c.Int(nullable: false, identity: true),
                        ContentVi = c.String(),
                        ContentEn = c.String(),
                        Type = c.Int(nullable: false),
                        Active = c.Boolean(nullable: false),
                        CreatedTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.ContentId);
            
            CreateTable(
                "Contact",
                c => new
                    {
                        ContactId = c.Int(nullable: false, identity: true),
                        CommonId = c.Int(nullable: false),
                        Body = c.String(),
                        Email = c.String(),
                        Active = c.Boolean(nullable: false),
                        CreatedTime = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.ContactId)
                .ForeignKey("Common", t => t.CommonId, cascadeDelete: true)
                .Index(t => t.CommonId);
            
            CreateTable(
                "Common",
                c => new
                    {
                        CommonId = c.Int(nullable: false, identity: true),
                        Content = c.String(),
                        ContentEn = c.String(),
                        Type = c.String(),
                        Images = c.String(),
                        CreatedTime = c.DateTime(nullable: false),
                        Status = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.CommonId);
            
            CreateTable(
                "StoreSecure",
                c => new
                    {
                        StoreSecureId = c.Int(nullable: false, identity: true),
                        ConfigStorePayto = c.String(),
                        ConfigMachentStoreName = c.String(),
                        ConfigSecureWord = c.String(),
                    })
                .PrimaryKey(t => t.StoreSecureId);
            
            CreateTable(
                "Country",
                c => new
                    {
                        CountryId = c.Int(nullable: false, identity: false),
                        CountryName = c.String(),
                    })
                .PrimaryKey(t => t.CountryId);
            
        }
        
        public override void Down()
        {
            DropIndex("Contact", new[] { "CommonId" });
            DropIndex("Chat", new[] { "UserId" });
            DropIndex("UserBet", new[] { "BetDetailId" });
            DropIndex("UserBet", new[] { "UserId" });
            DropIndex("BetDetail", new[] { "BetId" });
            DropIndex("Match", new[] { "LeagueId" });
            DropIndex("Match", new[] { "AwayTeamId" });
            DropIndex("Match", new[] { "HomeTeamId" });
            DropIndex("Bet", new[] { "UserId" });
            DropIndex("Bet", new[] { "MatchId" });
            DropIndex("SecureUser", new[] { "UserId" });
            DropIndex("WithDraw", new[] { "UserId" });
            DropIndex("Deposit", new[] { "UserId" });
            DropIndex("SecurityLog", new[] { "UserId" });
            DropForeignKey("Contact", "CommonId", "Common");
            DropForeignKey("Chat", "UserId", "User");
            DropForeignKey("UserBet", "BetDetailId", "BetDetail");
            DropForeignKey("UserBet", "UserId", "User");
            DropForeignKey("BetDetail", "BetId", "Bet");
            DropForeignKey("Match", "LeagueId", "League");
            DropForeignKey("Match", "AwayTeamId", "SoccerTeam");
            DropForeignKey("Match", "HomeTeamId", "SoccerTeam");
            DropForeignKey("Bet", "UserId", "User");
            DropForeignKey("Bet", "MatchId", "Match");
            DropForeignKey("SecureUser", "UserId", "User");
            DropForeignKey("WithDraw", "UserId", "User");
            DropForeignKey("Deposit", "UserId", "User");
            DropForeignKey("SecurityLog", "UserId", "User");
            DropTable("Country");
            DropTable("StoreSecure");
            DropTable("Common");
            DropTable("Contact");
            DropTable("Content");
            DropTable("Chat");
            DropTable("UserBet");
            DropTable("BetDetail");
            DropTable("League");
            DropTable("SoccerTeam");
            DropTable("Match");
            DropTable("Bet");
            DropTable("SecureUser");
            DropTable("WithDraw");
            DropTable("Deposit");
            DropTable("SecurityLog");
            DropTable("User");
        }
    }
}
